import type { Datum, EnterpriseDetail, EnterpriseListData, EnterpriseListParams, EnterpriseParams, EnterpriseParamsEdit, Industry, RentBuilding, RentParams } from "@/types/enterprise";
import service, { request } from "@/utils/reuqest";





export const getEnterpriseListAPI = (params:EnterpriseListParams) =>{
  return request <EnterpriseListData>('park/enterprise','GET',params)
}

export const getIndustryListAPI = () => {
  return request<Industry[]>('/park/industry')
 
 }

//  添加企业
 export const createEnterpriseAPI = (data:EnterpriseParams) =>{
  return request('/park/enterprise','POST',data)
 }

//  获取企业详情
export const getEnterpriseDetailAPI = (id:string) =>{
  return request<EnterpriseDetail>(`park/enterprise/${id}`)
}

// 封装获取楼宇列表接口

export const getRentBuildListAPI= async()=>{
  return request<RentBuilding[]>('park/rent/building')
}

// 给当前企业添加合同
export const createRentAPI = (data:RentParams) =>{
  return request('/park/enterprise/rent','POST',data)
}

// 获取企业下合同列表
export const getRentListAPI = (id:number) =>{
  return request<Datum[]>(`/park/enterprise/rent/${id}`)
}


/**
 * 退租
 * @param {合同id} rentId
 * @returns
 */
export const outRentAPI = (rentId: string)=> {
  return request(`/park/enterprise/rent/${rentId}`, 'PUT')
}

// 删除合同
export const deleteRentAPI = (rentId:string) =>{
  return request(`/park/enterprise/rent/${rentId}`,'DELETE')
}


// 园区管理-编辑企业 业务逻辑
export const updateEnterpriseAPI = (data:EnterpriseParamsEdit)=>{
  return request ('/park/enterprise','PUT',data)
}


// 删除企业

export const delEnterpriseAPI = (id:string) =>{
  return request(`park/enterprise/${id}`,'DELETE')
}


// 下载文件合同
export const downloadContract = (id:number) =>{
  // 普通的写法
  // return request (`/download/${id}`)

  return service.request<null,Blob>({
    method:'GET',
    url:`/download/${id}`,
    responseType:'blob' 
  })
}
